package com.example.WEB;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class UserDao {
    PreparedStatement preparedStatement=null;
    Connection connection=null;
    public void operatingDatabase(User user) throws Exception{
       try {
           connection=DBUtil.getConnection();
           String sql="insert into t_user(user_name,password,nick_name) values(?,?,?)";
           preparedStatement=connection.prepareStatement(sql);
           preparedStatement.setString(1,user.getUserName());
           preparedStatement.setString(2,user.getPassword());
           preparedStatement.setString(3,user.getNickName());
           int i= preparedStatement.executeUpdate();
           System.out.println("影响了"+i+"条");
       }catch (Exception e){
           e.printStackTrace();
       }finally {
           try {
               if(preparedStatement!=null){
                   preparedStatement.close();
               }
               if (connection!=null){
                   connection.close();
               }
           }catch (Exception e){
               e.printStackTrace();
           }
       }

    }
}
